package com.ruoyi.system.controller;

import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.CpProject;
import com.ruoyi.system.domain.MgNews;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RegistrationInformation;
import com.ruoyi.system.service.IRegistrationInformationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报名信息Controller
 *
 * @author zhangjinlei
 * @date 2022-04-25
 */
@RestController
@RequestMapping("/system/pInformation")
public class RegistrationInformationController<TableDataDetail> extends BaseController
{
    @Autowired
    private IRegistrationInformationService registrationInformationService;

    /**
     * 查询报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:pInformation:list')")
    @GetMapping("/list")
    public TableDataInfo list(RegistrationInformation registrationInformation)
    {
        startPage();
        List<RegistrationInformation> list = registrationInformationService.selectRegistrationInformationList(registrationInformation);
        return getDataTable(list);
    }

    /**
     * 查询选手名字 下拉框
     */
    @PostMapping("/palerList")
    public TableDataInfo  palerList (RegistrationInformation registrationInformation){
        List<RegistrationInformation> palerInfoList = registrationInformationService.selectPalerList(registrationInformation);
        return  getDataTable(palerInfoList);
    }

    /**
     * 审核报名信息
     * @param registrationInformation
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:pInformation:aduit')")
    @PostMapping( "/audit")
    public AjaxResult audit(@RequestBody RegistrationInformation registrationInformation)
    {
        return toAjax(registrationInformationService.auditRegistrationInformation(registrationInformation));
    }



    /**
     * 查询个人选手详细信息
     */
    @GetMapping ("/pInformationDetail")
    public TableDataInfo pInformationDetail (RegistrationInformation registrationInformation){
        List<RegistrationInformation> list = registrationInformationService.selectRegistrationInformationDetailList(registrationInformation);
        return getDataTable(list);
    }


    /**
     * 导出报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:pInformation:export')")
    @Log(title = "报名信息", businessType = BusinessType.EXPORT)
    public void export(HttpServletResponse response, RegistrationInformation registrationInformation)
    {
        List<RegistrationInformation> list = registrationInformationService.selectRegistrationInformationList(registrationInformation);
        ExcelUtil<RegistrationInformation> util = new ExcelUtil<RegistrationInformation>(RegistrationInformation.class);
        util.exportExcel(response, list, "报名信息数据");
    }

    /**
     * 获取报名信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pInformation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(registrationInformationService.selectRegistrationInformationById(id));
    }

    /**
     * 新增报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:pInformation:add')")
    @Log(title = "报名信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RegistrationInformation registrationInformation) throws Exception {
        return toAjax(registrationInformationService.insertRegistrationInformation(registrationInformation));
    }

    /**
     * 修改报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:pInformation:edit')")
    @Log(title = "报名信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RegistrationInformation registrationInformation)
    {
        return toAjax(registrationInformationService.updateRegistrationInformation(registrationInformation));
    }

    /**
     * 删除报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:pInformation:remove')")
    @Log(title = "报名信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(registrationInformationService.deleteRegistrationInformationByIds(ids));
    }
}
